import QtQuick 2.1
import QtQuick.Controls 1.0
import QtQuick.Window 2.0
import QtQuick.Dialogs 1.0
import QtQuick.Controls.Styles 1.0

Item {

    property int editIndex

    function calcSaveBonus(level, category) {
        switch (category)
        {
        case 1:
            return (level/3);

        case 2:
            return (level/2)+2;

        default:
            return -1;
        }
    }

    function calcBaseAttackBonus(level, category) {
        switch (category)
        {
        case 0:
            return (level-1)/2;

        case 1:
            return (level-1) - ((level-1)/4);

        case 2:
            return level;

        default:
            return -1;
        }
    }


    TitleText {
        id: titleText
        color: "white"

        text: characterModel.get(editIndex).name

        anchors.top: parent.top
        anchors.right: parent.right
        anchors.left: parent.left
    }

    Column {
        anchors.top: titleText.bottom
        anchors.left: parent.left
        anchors.right: parent.right
        anchors.bottom: parent.bottom
        anchors.topMargin: 12
        anchors.leftMargin: 9
        anchors.rightMargin: 9
        spacing: 9

        Column
        {
            anchors.left: parent.left
            anchors.right: parent.right
            spacing: 9

            Row {
                anchors.left: parent.left
                anchors.right: parent.right
                spacing: 3
                Text {
                    color: "white"
                    text: "Hit Die:"
                    font.bold: true
                }
                Text {
                    color: "white"
                    text: hitDiceList.get(characterModel.get(editIndex).hitDieIndex).name
                }
            }

            Row {
                anchors.left: parent.left
                anchors.right: parent.right
                spacing: 3
                Text {
                    color: "white"
                    text: "Skill Points:"
                    font.bold: true
                }
                Text {
                    color: "white"
                    text: skillPointsList.get(characterModel.get(editIndex).skillPointIndex).name + " (" + skillPointsList.get(characterModel.get(editIndex).skillPointIndex).value + ")"
                }
            }

            Row {
                anchors.left: parent.left
                anchors.right: parent.right
                spacing: 3
                Text {
                    color: "white"
                    text: "Class Skills:"
                    font.bold: true
                }
            }

        }

        Text {
            color: "white"
            wrapMode: Text.Wrap
            text: characterModel.get(editIndex).skills.split(";").join(", ")
            anchors.right: parent.right
            anchors.left: parent.left
        }

        Column {
            anchors.right: parent.right
            anchors.left: parent.left

            Rectangle {
                id: titleRectangle
                height: 20
                anchors.right: parent.right
                anchors.left: parent.left
                color: "darkred"
                border.color: "white"
                border.width: 1

                Row {
                    spacing: 6
                    anchors.fill: parent
                    anchors.leftMargin: 6

                    Text {
                        id: levelTitle
                        text: "Level"
                        color: "white"
                        font.bold: true
                        anchors.verticalCenter: parent.verticalCenter
                    }

                    /// \todo Class level header bonus selectors
                    /// \author Jussi
                    /// \date 2013-10-03
                    Repeater {
                        model: bonusList
                        delegate: Text {
                            text: acronym
                            color: "white"
                            font.bold: true
                            horizontalAlignment: Text.AlignHCenter
                            width: 30
                            anchors.verticalCenter: parent.verticalCenter
                        }
                    }

                    Text {
                        text: "Special Abilities"
                        color: "white"
                        font.bold: true
                        anchors.verticalCenter: parent.verticalCenter
                    }
                }

            }

            Repeater {
                id: rowRepeater
                model: 20

                delegate: Rectangle {
                    id: rowRectangle
                    height: 20
                    anchors.right: parent.right
                    anchors.left: parent.left
                    property int level: index+1

                    Row {
                        spacing: 6
                        anchors.fill: parent
                        anchors.leftMargin: 6

                        Text {
                            text: level
                            color: "white"
                            width: levelTitle.width
                            font.bold: true
                            anchors.verticalCenter: parent.verticalCenter
                            horizontalAlignment: Text.AlignHCenter
                        }

                        Repeater {
                            model: bonusList
                            delegate: Text {

                                /// \todo C++ calculation, which works because of type safety
                                /// \author Jussi
                                /// \date 2013-10-03
                                property int bonus: category == "attack" ? calcBaseAttackBonus(level, characterModel.get(editIndex).baseAttackIndex) : calcSaveBonus(level, 1)
                                text: "+" + bonus
                                color: "white"
                                width: 30
                                horizontalAlignment: Text.AlignHCenter
                                anchors.verticalCenter: parent.verticalCenter
                            }
                        }

                        /// \todo Class level special ability editing (add, edit, remove, select)
                        /// \author Jussi
                        /// \date 2013-10-03

                        Text {
                            color: "white"
                            font.bold: true
                            anchors.verticalCenter: parent.verticalCenter
                        }
                    }
                    MouseArea {
                        id: rowMouseArea
                        anchors.fill: parent
                        hoverEnabled:true
                    }
                    color: rowMouseArea.containsMouse ? "steelblue" : !(index%2) ? "transparent" : "#888888"

                }

            }


        }

    }

}
